package javase0906;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        //创建new user
        User user = new User("", "");
        Scanner scanner = new Scanner(System.in);
        //登录操作
        while (true) {
            System.out.println("请选择操作：");

            System.out.println("1.注册");
            System.out.println("2.登录");
            System.out.println("================================");
            int choice = scanner.nextInt();

            if (choice == 1) {
                //用户登录验证

                System.out.println("请输入用户名：");
                String username = scanner.next();
                System.out.println("请输入密码：");
                String password = scanner.next();


                //创建一个新的user对象并设置用户名和密码
                user = new User(username, password);
                System.out.println("注册成功！请登录。");
            }
            if (choice == 2) {
                //用户登录验证
                System.out.println("请输入用户名：");
                String username = scanner.next();
                System.out.println("请输入密码：");
                String password = scanner.next();


                if (user.authenticate(username, password)) {
                    System.out.println("登陆成功");
                    System.out.println("欢迎光临仁爱·卢布松");
                    System.out.println("================================");

                    //创建菜单
                    List<Dish> menu = new ArrayList<>();
                    new ClientBunny().initDish(menu);
                    /*menu.add(new Dish("精致海胆啫喱佐花椰菜", 299.9, "本店招牌，非常适合与香槟搭配。"));
                    menu.add(new Dish("经典黑松露塔", 669.9, "熏肉中加了松露沫，非常美味。"));
                    menu.add(new Dish("烟熏三文鱼佐鱼子酱", 198.9, "丰富的sauce加入了wasabi。"));
                    menu.add(new Dish("低温满煮乳鸽和鹅肝", 479.9, "是一道绝佳收尾的主菜。"));
                    menu.add(new Dish("白巧克力玫瑰配清酒啫喱及橘香果酱", 88.9, "即使吃了三小时的fine dining，也会被这道菜唤醒。"));
                    menu.add(new Dish("芒果千层塔，海盐焦糖及热带水果冰霜", 88.9, "芒果带着酸甜感，海盐焦糖的咸度吊出了芒果的甜度。"));
                    menu.add(new Dish("臭豆腐", 299.0, "咸"));
                    menu.add(new Dish("腐乳", 299.0, "咸"));
                    menu.add(new Dish("西红柿炒鸡蛋", 29.0, "咸"));
                    */
                    System.out.println("================================");

                    //显示菜单
                    System.out.println("菜单：");
                    for (int i = 0; i < menu.size(); i++) {
                        Dish dish = menu.get(i);
                        System.out.println((i + 1) + "." + dish.getName() + " - ￥" + dish.getPrice());
                        System.out.println("描述：" + dish.getDescription());
                        System.out.println();
                    }
                    //创建购物车
                    ShoppingCart shoppingCart = new ShoppingCart();
                    Scanner sc = new Scanner(System.in);
                    //用户登录成功后的操作，例如显示菜单点餐、生成订单等
                    while (true) {
                        System.out.println("请选择操作");
                        System.out.println("1.添加菜品");
                        System.out.println("2.清空购物车");
                        System.out.println("3.生成订单");
                        System.out.println("4.退出");
                        System.out.println("================================");
                        int choice1 = sc.nextInt();
                        sc.nextLine();
                        switch (choice1) {
                            case 1:
                                //添加菜品
                                System.out.println("请输入要点的菜品编号:");
                                int dishChoice = sc.nextInt();
                                sc.nextLine();
                                if (dishChoice >= 1 && dishChoice <= menu.size()) {
                                    Dish selectedDish = menu.get(dishChoice - 1);
                                    System.out.println("请输入菜品数量：");
                                    int quantity = sc.nextInt();
                                    sc.nextLine();
                                    selectedDish.setQuantity(quantity);
                                    //设置菜品数量
                                    shoppingCart.addDish(selectedDish, quantity);
                                    System.out.println("已将菜品加入购物车");
                                } else {
                                    System.out.println("输入的菜品无效");
                                }
                                break;
                            case 2:
                                //清空购物车：
                                shoppingCart.clearCart();
                                System.out.println("购物车已清空");
                                break;

                            case 3:
                                //生成订单：
                                shoppingCart.generateOrder();
                                List<Dish> orderedDishes = shoppingCart.getDishes();
                                double totalPrice = 0.0;
                                for (Dish dish : orderedDishes) {
                                    System.out.println("已点菜品：" + dish.getName());
                                    System.out.println("数量：" + dish.getQuantity());
                                    System.out.println("单价：" + dish.getPrice());
                                    double dishTotalPrice = dish.getQuantity() * dish.getPrice();
                                    System.out.println("该菜品总价：" + dishTotalPrice);
                                    totalPrice += dishTotalPrice;
                                    System.out.println();
                                }
                                System.out.println("已点所有菜品总价：" + totalPrice);
                                System.out.println("================================");
                                shoppingCart.clearCart();

                                break;
                            case 4:
                                //退出
                                System.exit(0);
                                break;
                            default:
                                System.out.println("无效的选择");
                                break;
                        }
                    }
                } else {
                    System.out.println("登陆失败");
                }
            }
        }
    }
}

